import numpy as np
import pandas as pd

x1=np.array([43,82,43,44,55,46,67])
x2=np.array([16,19,37,26,62,43,54])
x3=np.array([65,28,87,58,29,25,31])
x4=np.array([32,39,34,26,15,37,48])

#矩阵的转置
#np.matrix()生成一个矩阵
#将x1,x2,x3,x4四个向量合并存储为矩阵，并转置为列向量，T操作符是对矩阵进行转置
#data=np.matrix([x1,x2,x3,x4]).T#参数是一个列表，列表元素是四个向量元组
data = np.array([x1, x2, x3, x4]).T  # 使用np.array直接创建二维数组
print("转置的矩阵为：",data)

#ravel()将二维矩阵转化为一维矩阵
data1=np.round(data.mean(0),1).ravel()#mean(0)表示按列求均值
print(data1)
 

#计算均值
mean_=np.mean(data,axis=1)  # axis=1表示按行计算均值
print('均值为：', mean_)

#协方差矩阵
cov_=np.cov(np.matrix([x1,x2,x3,x4]))
print('协方差矩阵:','\n',cov_)
rou_=np.corrcoef(np.matrix([x1,x2,x3,x4]))
print('相关系数矩阵:','\n',rou_)

#测试筛选整除
a = np.arange(20).reshape([4,5])
print("a = \n", a)
print("a中能被3整除或者7整除的数字保留：")
print((a % 3 == 0) | (a % 7 == 0))
print("筛选后的结果：")
print(a[(a % 3 == 0) | (a % 7 == 0)])